/*
 * igo: com.cctv.igo.admin.scheduler.parser.TriggerManager.java Create On 2011-5-26 下午05:06:11 By Q-Wang
 * $Revision: 1.1 $
 */
package com.ctvit.scheduler.parser;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import org.quartz.Trigger;

import com.ctvit.scheduler.domain.QrtxTrigger;

/**
 * @author <a href="mailto:apeidou@gmail.com">Q-Wang</a>
 *
 */
public class TriggerManager {

	public static final List<TriggerParser> PARSERS = new ArrayList<TriggerParser>(){{
		add(new CronTriggerParser());
		add(new DateIntervalTriggerParser());
		add(new NthIncludeDayTriggerParser());
		add(new SimpleTriggerParser());
		add(new DefaultTriggerParser());
	}};

	public static Trigger parse(QrtxTrigger trigger) throws ParseException {
		if (trigger==null) {
			return null;
		}
		String type = trigger.getType();
		for (TriggerParser parser:PARSERS) {
			if (parser.support(type)) {
				return parser.parse(trigger);
			}
		}
		return null;
	}
}
